/*
 * Copyright 2022 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.seppiko.chart.utils

import org.seppiko.commons.logging.AbstractLogging
import org.slf4j.Logger
import org.slf4j.LoggerFactory

/**
 *
 * @author Leonard Woo
 */
class LoggingManager: AbstractLogging {

  companion object {
    val INSTANCE :LoggingManager = LoggingManager()
  }

  private lateinit var logger: Logger

  fun getLogger(name: String): LoggingManager {
    logger = LoggerFactory.getLogger(name)
    return this;
  }

  /**
   * Checks whether this Logger is enabled for the TRACE level.
   *
   * @return true if this Logger is enabled for level TRACE, false otherwise.
   */
  override fun isTraceEnable(): Boolean {
    return logger.isTraceEnabled
  }

  /**
   * Logs a message CharSequence with the TRACE level.
   *
   * @param message the message object to log.
   */
  override fun trace(message: CharSequence?) {
    logger.trace(message.toString())
  }

  /**
   * Logs a CharSequence at the TRACE level including the stack trace of the Throwable throwable passed as parameter.
   *
   * @param message the message object to log.
   * @param cause the Throwable to log, including its stack trace.
   */
  override fun trace(message: CharSequence?, cause: Throwable?) {
    logger.trace(message.toString(), cause)
  }

  /**
   * Checks whether this Logger is enabled for the DEBUG level.
   *
   * @return true if this Logger is enabled for level DEBUG, false otherwise.
   */
  override fun isDebugEnable(): Boolean {
    return logger.isDebugEnabled
  }

  /**
   * Logs a message CharSequence with the DEBUG level.
   *
   * @param message the message object to log.
   */
  override fun debug(message: CharSequence?) {
    logger.debug(message.toString())
  }

  /**
   * Logs a CharSequence at the DEBUG level including the stack trace of the Throwable throwable passed as parameter.
   *
   * @param message the message object to log.
   * @param cause the Throwable to log, including its stack trace.
   */
  override fun debug(message: CharSequence?, cause: Throwable?) {
    logger.debug(message.toString(), cause)
  }

  /**
   * Checks whether this Logger is enabled for the INFO level.
   *
   * @return true if this Logger is enabled for level INFO, false otherwise.
   */
  override fun isInfoEnable(): Boolean {
    return logger.isInfoEnabled
  }

  /**
   * Logs a message CharSequence with the INFO level.
   *
   * @param message the message object to log.
   */
  override fun info(message: CharSequence?) {
    logger.info(message.toString())
  }

  /**
   * Logs a CharSequence at the INFO level including the stack trace of the Throwable throwable passed as parameter.
   *
   * @param message the message object to log.
   * @param cause the Throwable to log, including its stack trace.
   */
  override fun info(message: CharSequence?, cause: Throwable?) {
    logger.info(message.toString(), cause)
  }

  /**
   * Checks whether this Logger is enabled for the WARN level.
   *
   * @return true if this Logger is enabled for level WARN, false otherwise.
   */
  override fun isWarnEnable(): Boolean {
    return logger.isWarnEnabled
  }

  /**
   * Logs a message CharSequence with the WARN level.
   *
   * @param message the message object to log.
   */
  override fun warn(message: CharSequence?) {
    logger.warn(message.toString())
  }

  /**
   * Logs a CharSequence at the WARN level including the stack trace of the Throwable throwable passed as parameter.
   *
   * @param message the message object to log.
   * @param cause the Throwable to log, including its stack trace.
   */
  override fun warn(message: CharSequence?, cause: Throwable?) {
    logger.warn(message.toString(), cause)
  }

  /**
   * Checks whether this Logger is enabled for the ERROR level.
   *
   * @return true if this Logger is enabled for level ERROR, false otherwise.
   */
  override fun isErrorEnable(): Boolean {
    return logger.isErrorEnabled
  }

  /**
   * Logs a message CharSequence with the ERROR level.
   *
   * @param message the message object to log.
   */
  override fun error(message: CharSequence?) {
    logger.error(message.toString())
  }

  /**
   * Logs a CharSequence at the ERROR level including the stack trace of the Throwable throwable passed as parameter.
   *
   * @param message the message object to log.
   * @param cause the Throwable to log, including its stack trace.
   */
  override fun error(message: CharSequence?, cause: Throwable?) {
    logger.error(message.toString(), cause)
  }
}